<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\ItemReviews
 *
 * @property int $id
 * @property int $uid
 * @property int $itemid
 * @property int|null $order_id
 * @property int $stars
 * @property string|null $message
 * @property int|null $created_at
 * @property-read \App\Models\Item $item
 * @property-read \App\Models\Order|null $order
 * @property-read \App\Models\User $user
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ItemReviews whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ItemReviews whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ItemReviews whereItemid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ItemReviews whereMessage($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ItemReviews whereOrderId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ItemReviews whereStars($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ItemReviews whereUid($value)
 * @mixin \Eloquent
 * @property int $rate_type 1=好评,2=中评,3=差评
 * @property string|null $images
 * @property int $image_count
 * @property string|null $add_message
 * @property string|null $add_images
 * @property int $add_at
 * @property int $add_image_count
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ItemReviews whereAddAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ItemReviews whereAddImageCount($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ItemReviews whereAddImages($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ItemReviews whereAddMessage($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ItemReviews whereImageCount($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ItemReviews whereImages($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ItemReviews whereRateType($value)
 * @property string|null $seller_message
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ItemReviews whereSellerMessage($value)
 */
class ItemReviews extends Model
{
    protected $table = 'item_reviews';
    protected $primaryKey = 'id';
    protected $guarded = ['id'];

    public $timestamps = false;

    public static function boot()
    {
        parent::boot(); // TODO: Change the autogenerated stub
        static::creating(function ($model){
            if (!$model->created_at) $model->created_at = time();
        });
    }

    public function order()
    {
        return $this->belongsTo(Order::class, 'order_id', 'order_id');
    }

    public function user()
    {
        return $this->belongsTo(User::class, 'uid', 'uid');
    }

    public function item()
    {
        return $this->belongsTo(Item::class, 'itemid', 'itemid');
    }
}
